package com.adee.nowcoder.huawei;

import java.util.Scanner;

public class T005_HJ5 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int len = str.length();
            int bin = 0;
            for (int i = len-1; i > 1; i--) {
                char c = str.charAt(i);
                int tmpBin = 0;
                if(c >= 'A' && c <= 'F') {
                    tmpBin = c-'A'+10;
                }else if (c >= '0' && c <= '9') {
                    tmpBin = c-'0';
                }else {
                    System.out.println("error");
                }
                bin += tmpBin*(1<<((len-1-i)*4));
            }
            System.out.println(bin);
        }
    }
}
